<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>会计系统-损益</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="keywords" content="会计系统-损益">
<meta name="description" content="会计系统-损益">
<meta name="author" content="yinqi">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/materialdesignicons.min.css" rel="stylesheet">
<link href="css/style.min.css" rel="stylesheet">
</head>
  <style>
    .col-lg-12{
      margin: auto;
    top: 17px;
    left: 0;
    bottom: 0;
    right: 0;
    position: absolute;
    }
  </style>
<body>
<div class="lyear-layout-web" id="app">
  <div class="lyear-layout-container">
    <!--左侧导航-->

    <!--End 左侧导航-->
    
    <!--头部信息-->
 
    <!--End 头部信息-->
    
    <!--页面主要内容-->

    <main class="lyear-layout-content" >
      <div class="container-fluid">
        
        <div class="row">
          <div class="col-lg-12" >
            <div class="card">
              <div class="card-toolbar clearfix">
                <div class="toolbar-btn-action">
                  <!-- <a class="btn btn-primary m-r-5" data-toggle="modal"   data-target="#myModal" ><i class="mdi mdi-plus" ></i> 新增</a> -->
                  <!-- <el-button  class="btn btn-danger" type="warning" style="background-color:#f96868;" @click="removeBatch(sels)" :disabled="this.sels.length === 0||this.disabled"><i class="mdi mdi-window-close"></i>批量删除</el-button> -->
                </div>
              </div>
              <div class="card-body">
                
                <div class="table-responsive">
                  <table class="table table-bordered">
                    <template>
                      <el-table
                        v-loading="loading"
                        element-loading-text="拼命加载中"
                        :data="list"
                        style="width: 100%">
                        <el-table-column
                          prop="kmCoding"
                          label="科目编码"
                          width="180">
                        </el-table-column>
                        <el-table-column
                          prop="kmName"
                          label="科目名称"
                          width="180">
                        </el-table-column>
                        <el-table-column
                          prop="kmCode"
                          label="助记码"
                          width="180">
                        </el-table-column>
                        <el-table-column
                          prop="kmPrice"
                          label="余额方向">
                          <template slot-scope="scope">
                            <span>{{config2.gzdStateList[scope.row.kmPrice]}}</span>
                         </template>
                        </el-table-column>
                        <el-table-column
                        prop="kmNumber"
                        label="数量核算">
                      </el-table-column>
                      <el-table-column
                      prop="kmAccounting"
                      label="辅助核算">
                      <template slot-scope="scope">
                        <span>{{config3.gzdStateList[scope.row.kmAccounting]}}</span>
                     </template>
                    </el-table-column>
                    <el-table-column
                    prop="kmPrice"
                    label="外币核算">
                    <template slot-scope="scope">
                      <span>{{config4.gzdStateList[scope.row.kmForeign]}}</span>
                   </template>
                  </el-table-column>
                        <el-table-column
                        prop="kmState"
                        label="状态">
                        <template slot-scope="scope">
                          <span>{{config.gzdStateList[scope.row.kmState]}}</span>
                       </template>
                      </el-table-column>
                  <el-table-column label="操作" align="center" min-width="100">
              　　　　<template slot-scope="scope">
                          <div class="btn-group">
                            <a class="btn btn-xs btn-default" @click="add(scope.row.kmId)"  type="button" data-toggle="modal" data-target="#myModal" title="新增" data-toggle="tooltip">新增</a>
                            <a class="btn btn-xs btn-default" @click="edit(scope.row.kmId)"  type="button" data-toggle="modal" data-target="#myModalup" title="编辑" data-toggle="tooltip">编辑</a>
                            <a class="btn btn-xs btn-default" @click="del(scope.row.kmId)" type="button"  title="删除" data-toggle="tooltip">删除</a>
                          </div>
              　　　　</template>
              　　</el-table-column>
                      </el-table>
                      
                    </template>
                  </table>
                </div>
                <!-- 添加模态框（Modal） -->
                <form action=""  class="form-horizontal" role="form">
                  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                      <div class="modal-dialog">
                          <div class="modal-content" style="width: 850px;
                          margin-left: -185px;">
                              <div class="modal-header">
                                  <h4 class="modal-title" id="myModalLabel">
                                      科目损益新增
                                  </h4>
                                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                      &times;
                                  </button>
                              </div>
                                <div class="modal-body" style="height: 100%; float: left; width: 400px;" >

                                  <div class="form-group">
                                    <label for="lastname" class="col-sm-3 control-label">科目编号</label>
                                    <div class="col-sm-7">
                                      <input class="form-control" type="text" v-model="user2.kmCoding" placeholder="科目编号">
                                    </div>
                                     </div>

                                     <div class="form-group">
                                      <label for="lastname" class="col-sm-3 control-label">上级科目</label>
                                      <div class="col-sm-7">
                                        <input class="form-control" type="text" v-model="user2.kmName" disabled  placeholder="上级科目">
                                      </div>
                                  </div>
                                  <div class="form-group">
                                    <label for="lastname" class="col-sm-3 control-label">余额方向</label>
                                    <div class="col-sm-7" style="margin-top: 5px;">
                                      <template>
                                        <el-radio v-model="user2.kmPrice" label="0">借</el-radio>
                                        <el-radio v-model="user2.kmPrice" label="1">贷</el-radio>
                                      </template>
                                    </div>
                                </div>

                                </div>

                                <div class="modal-body" style="height: 100%; float: left; width: 400px;">
                                  <div class="form-group">
                                    <label for="lastname" class="col-sm-3 control-label">科目名称</label>
                                    <div class="col-sm-7">
                                      <input class="form-control" type="text" v-model="user.kmName"  placeholder="科目名称">
                                    </div>
                                </div>
                               
                              <div class="form-group">
                                <label for="lastname" class="col-sm-3 control-label">科目类别</label>
                                <div class="col-sm-7">
                                  <input class="form-control" type="text" value="损益类" disabled  placeholder="科目类别">
                                </div>
                            </div>
                           
                          <div class="form-group">
                            <label for="lastname" class="col-sm-3 control-label">科目状态</label>
                            <div class="col-sm-7" style="margin-top: 5px;">
                              <template>
                                <el-radio v-model="user2.kmState" label="1">正常</el-radio>
                                <el-radio v-model="user2.kmState" label="0">不可用</el-radio>
                              </template>
                            </div>
                          </div>
                          </div>
                                
                            <div class="form-group" style="margin-left: -55px;">
                              <label for="lastname" class="col-sm-3 control-label">数量核算   计算单位：</label>
                              <div class="col-sm-7">
                                <input class="form-control" type="text" v-model="user.kmNumber"  style="width: 100px;">
                              </div>
                            </div>
                            <div class="form-group" style="margin-left: -156px;">
                              <label for="lastname" class="col-sm-3 control-label">辅助核算</label>
                              <div class="col-sm-7">
                                <template>
                                  <el-checkbox v-model="user.kmAccounting" >客户</el-checkbox>
                                  <el-checkbox v-model="user.kmAccounting1" >供应商</el-checkbox>
                                  <el-checkbox v-model="user.kmAccounting2" >职员</el-checkbox>
                                  <el-checkbox v-model="user.kmAccounting3" >部门</el-checkbox>
                                  <el-checkbox v-model="user.kmAccounting4" >项目</el-checkbox>
                                  <el-checkbox v-model="user.kmAccounting5" >存货</el-checkbox>
                                </template>
                              </div>
                            </div>
                            <div class="form-group" style="margin-left: -156px;">
                              <label for="lastname" class="col-sm-3 control-label">外币核算</label>
                              <div class="col-sm-7">
                                <template>
                                  <el-checkbox v-model="user.kmForeign" >人民币</el-checkbox>
                                </template>
                              </div>
                            </div>
                                  
                              <div class="modal-footer">
                                  <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                  <el-button id="button" data-dismiss="modal"  class="btn btn-default" type="primary" :loading="loading" @click="subjectsadd()"  >提交</el-button>

                              </div>
                          </div>
                      </div>
                  </div>
                </form>
<!-- 修改模态框（Modal） -->
<form action=""  class="form-horizontal" role="form">
  <div class="modal fade" id="myModalup" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
          <div class="modal-content" style="width: 850px;
          margin-left: -185px;">
              <div class="modal-header">
                  <h4 class="modal-title" id="myModalLabel">
                    科目损益编辑
                  </h4>
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                      &times;
                  </button>
              </div>
              <div class="modal-body" style="height: 100%; float: left; width: 400px;" >

                <div class="form-group">
                  <label for="lastname" class="col-sm-3 control-label">科目编号</label>
                  <div class="col-sm-7">
                    <input class="form-control" type="text" v-model="user1.kmCoding" placeholder="科目编号">
                  </div>
                   </div>

                   <div class="form-group">
                    <label for="lastname" class="col-sm-3 control-label">上级科目</label>
                    <div class="col-sm-7">
                      <input class="form-control" type="text" v-model="user1.kmName" disabled  placeholder="上级科目">
                    </div>
                </div>
                <div class="form-group">
                  <label for="lastname" class="col-sm-3 control-label">余额方向</label>
                  <div class="col-sm-7" style="margin-top: 5px;">
                    <template>
                      <el-radio v-model="user1.kmPrice" label="0">借</el-radio>
                      <el-radio v-model="user1.kmPrice" label="1">贷</el-radio>
                    </template>
                  </div>
              </div>

              </div>

              <div class="modal-body" style="height: 100%; float: left; width: 400px;">
                <div class="form-group">
                  <label for="lastname" class="col-sm-3 control-label">科目名称</label>
                  <div class="col-sm-7">
                    <input class="form-control" type="text" v-model="user1.kmName"  placeholder="科目名称">
                  </div>
              </div>
             
            <div class="form-group">
              <label for="lastname" class="col-sm-3 control-label">科目类别</label>
              <div class="col-sm-7">
                <input class="form-control" type="text" value="损益类" disabled  placeholder="科目类别">
              </div>
          </div>
         
        <div class="form-group">
          <label for="lastname" class="col-sm-3 control-label">科目状态</label>
          <div class="col-sm-7" style="margin-top: 5px;">
            <template>
              <el-radio v-model="user1.kmState" label="1">正常</el-radio>
              <el-radio v-model="user1.kmState" label="0">不可用</el-radio>
            </template>
          </div>
        </div>
        </div>
              
          <div class="form-group" style="margin-left: -55px;">
            <label for="lastname" class="col-sm-3 control-label">数量核算   计算单位：</label>
            <div class="col-sm-7">
              <input class="form-control" type="text" v-model="user1.kmNumber"  style="width: 100px;">
            </div>
          </div>
          <div class="form-group" style="margin-left: -156px;">
            <label for="lastname" class="col-sm-3 control-label">辅助核算</label>
            <div class="col-sm-7">
              <template>
                <el-checkbox v-model="user3.kmAccounting" >客户</el-checkbox>
                <el-checkbox v-model="user3.kmAccounting1" >供应商</el-checkbox>
                <el-checkbox v-model="user3.kmAccounting2" >职员</el-checkbox>
                <el-checkbox v-model="user3.kmAccounting3" >部门</el-checkbox>
                <el-checkbox v-model="user3.kmAccounting4" >项目</el-checkbox>
                <el-checkbox v-model="user3.kmAccounting5" >存货</el-checkbox>
              </template>
            </div>
          </div>
          <div class="form-group" style="margin-left: -156px;">
            <label for="lastname" class="col-sm-3 control-label">外币核算</label>
            <div class="col-sm-7">
              <template>
                <el-checkbox v-model="user3.kmForeign"  label="1">人民币</el-checkbox>
              </template>
            </div>
          </div>
              <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                  <el-button id="button" data-dismiss="modal"  class="btn btn-default" type="primary" :loading="loading" @click="subjectsup()">提交</el-button>

              </div>
          </div>
      </div>
  </div>
</form>
              </div>
            </div>
          </div>
          
        </div>
        
      </div>
      
    </main>
    <!--End 页面主要内容-->
  </div>
</div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script src="https://cdn.bootcss.com/vue/2.6.9/vue.min.js"></script>
<script src="https://cdn.bootcss.com/axios/0.19.0/axios.min.js"></script>

<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>

<script>
  new Vue({
    el:"#app",
  data:{
    config :{
        gzdStateList: {
            0: '禁用',
            1: '启用',
            },  
    },
    config2 :{
        gzdStateList: {
            0: '借',
            1: '贷',
            },  
    },
    config3 :{
        gzdStateList: {
            1: '客户',
            2: '供应商',
            3: '职员',
            4: '部门',
            5: '项目',
            6: '存货',
            },  
    },
    config4 :{
        gzdStateList: {
            1: '外币',
            },  
    },
    checked: true,
    list:[],
    menu:[],
    loading: false,
    account:{},
    currentPage:1, //当前页码
    size:5, 
    totals:"",
    prePage:1,
    nextPage:1,
    totalPage:1, //总页数

    disabled:true,
    user:{
      kmCoding:"",
      kmName:"",
      kmCode:"",
      kmPrice:"",
      kmState:"",
      kmAccounting:"",
      kmForeign:""
    },
    user1:{
      kmAccounting:[],
      kmForeign:[]
    },
    user2:{
     
    },
    user3:{
      kmAccounting:['1'],
      
    },
    roleid:"",
    menuup:{}
  },
  created () {
    this.getlist(1);
  },
  methods: {
    getlist(currentPage){
      this.loading=true;
      setTimeout(() => {
      this.loading = false;
        axios.get("http://localhost:8888/subjects/profit")
        .then(res => {
          this.list = res.data
          console.log(res)
        })
        .catch(err => {
          console.error(err); 
        })
       }, 2000);
    },
    subjectsadd(){
      this.user.kmCoding = this.user2.kmCoding
      this.user.kmPrice = this.user2.kmPrice
      this.user.kmState = this.user2.kmState
      
      var chars = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','0','p','q','r','s','t','u','v','w','x','y','z'];
       var res = "";
       for(var i = 0; i < 4 ; i ++) {
         var id = Math.ceil(Math.random()*35);
         res += chars[id];
       }
     
      this.user.kmCode = this.user2.kmCode+"_"+res
      if(this.user.kmForeign == true){
        this.user.kmForeign = "1"
      }else{
        this.user.kmForeign = "0"
      }

      if(this.user.kmAccounting == true){
        this.user.kmAccounting = "1"
      }else if(this.user.kmAccounting1 == true){
        this.user.kmAccounting = "2"
      }else if(this.user.kmAccounting2 == true){
        this.user.kmAccounting = "3"
      }else if(this.user.kmAccounting3 == true){
        this.user.kmAccounting = "4"
      }else if(this.user.kmAccounting4 == true){
        this.user.kmAccounting = "5"
      }else if(this.user.kmAccounting5 == true){
        this.user.kmAccounting = "6"
      }else{
        this.user.kmAccounting = "0"
      }

      // alert(JSON.stringify(this.user))
      axios.post("http://localhost:8888/subjects/insert",this.user)
      .then(res => {
        console.log(res)

        this.loading=true;
       setTimeout(() => {
        this.loading = false;

        this.$message({
        message: '恭喜你，科目损益新增成功！！',
        type: 'success'
        });

      }, 2000);
      this.getlist(1);
      })
      .catch(err => {
        console.error(err); 
        this.$message.error('科目损益新增失败！！！');
      })

    },
    subjectsup(){
      this.user1.kmAccounting = this.user3.kmAccounting
      this.user1.kmForeign = this.user3.kmForeign
      axios.post("http://localhost:8888/subjects/update",this.user1)
      .then(res => {
        console.log(res)

        this.loading=true;
       setTimeout(() => {
        this.loading = false;

        this.$message({
        message: '恭喜你，科目损益编辑成功！！',
        type: 'success'
        });

      }, 2000);
      this.getlist(1);
      })
      .catch(err => {
        console.error(err); 
        this.$message.error('科目损益编辑失败！！！');
      })
    },
    add(id){
     axios.get("http://localhost:8888/subjects/selectByPrimaryKey/"+id)
      .then(res => {
        // alert(JSON.stringify(res.data))
        this.user2 = res.data
        console.log(res)
      })
      .catch(err => {
        console.error(err); 
      })
    },
    edit(id){
      axios.get("http://localhost:8888/subjects/selectByPrimaryKey/"+id)
      .then(res => {
        // alert(JSON.stringify(res.data))
        this.user1 = res.data

        if(this.user1.kmForeign == 1){
          this.user3.kmForeign = true;
        }
        if(this.user1.kmAccounting == 1){
          this.user3.kmForeign = true;
        }else if(this.user1.kmAccounting == 2){
          this.user3.kmAccounting1 = true;
        }else if(this.user1.kmAccounting == 3){
          this.user3.kmAccounting2 = true;
        }else if(this.user1.kmAccounting == 4){
          this.user3.kmAccounting3 = true;
        }else if(this.user1.kmAccounting == 5){
          this.user3.kmAccounting4 = true;
        }else if(this.user1.kmAccounting == 6){
          this.user3.kmAccounting5 = true;
        }

        this.user3.kmAccounting = this.user1.kmAccounting
        // alert(this.user1.kmForeign)
        console.log(res)
      })
      .catch(err => {
        console.error(err); 
      })
    },
    del(id){

      this.$confirm('确定要删除科目损益吗?','提示').then(() =>{
        axios.delete("http://localhost:8888/subjects/deleteByPrimaryKey/"+id)
      .then(res => {
        console.log(res)

        this.loading=true;
       setTimeout(() => {
        this.loading = false;

        this.$message({
        message: '恭喜你，科目损益删除成功！！',
        type: 'success'
        });
      }, 2000);
      this.getlist(1);
      })
      .catch(err => {
        console.error(err); 
        this.$message.error('科目损益删除失败！！！');
      })
    
      }).catch(()=>{}); 

    }
      
  }
  })
</script>
</body>
</html>